package com.liu.security.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.security.mapper.DUserMapper;
import com.liu.security.mapper.RoleMapper;
import com.liu.security.pojo.DUser;
import com.liu.security.pojo.Role;
import com.liu.security.service.DUserService;
import com.liu.security.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.DuplicateFormatFlagsException;

/**
 * Created by shi860715@126.com
 * Date 2021/8/13 9:57
 * Description
 */
@Service
@Slf4j
public class DUserServiceImp extends ServiceImpl<DUserMapper, DUser> implements DUserService {


    @Autowired
    PasswordEncoder passwordEncoder;

    @Autowired
    DUserMapper dUserMapper;

    @Override
    @Transactional
    public Boolean add(DUser user) {
        user.setPassword(passwordEncoder.encode(user.getPassword()));

        int id =dUserMapper.insert(user);
        log.info("保存结果",id);

        return true;
    }

    @Override
    public DUser getDuserRoles(Integer id) {
        return dUserMapper.getUserRoles(id);
    }

    @Override
    public DUser getUserPermission(Integer id) {
        return dUserMapper.getUserPermission(id);
    }
}
